package com.ijustyce.denoise.fragment;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageButton;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.view.NestedScrollingParent;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


import com.ijustyce.denoise.Activity.FileActivity;
import com.ijustyce.denoise.Activity.OptimizeActivity;
import com.ijustyce.denoise.Activity.PlayActivity;
import com.ijustyce.denoise.Activity.UseCamera;
import com.ijustyce.denoise.Adapter.ButtonAdapter;
import com.ijustyce.denoise.Adapter.MyAdapter;
import com.ijustyce.denoise.DemoActivity.TransActivity;
import com.ijustyce.denoise.Items.buttons;
import com.ijustyce.denoise.Items.goods;
import com.ijustyce.denoise.R;
import com.ijustyce.denoise.Utils.GlideImageLoader;
import com.xuexiang.xui.widget.layout.linkage.ChildLinkageEvent;
import com.xuexiang.xui.widget.layout.linkage.ILinkageScroll;
import com.xuexiang.xui.widget.layout.linkage.LinkageScrollHandler;
import com.youth.banner.Banner;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class IndexFragment extends Fragment  implements NestedScrollingParent {
    private goods goods;
    private View view;
    private Banner banner;
    List<goods> goodsList = new ArrayList<>();
    private List<buttons> buttonList = new ArrayList<>();
    private int i = 0;

    private ImageButton btn1;
    private ImageButton btn2;
    private ImageButton btn3;
    private ImageButton btn4;
    private EditText text;
    private RecyclerView recyclerView;
    private RecyclerView recyclerView_head;
    LinearLayoutManager linearLayoutManager_head;

    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);//先进oncreate下一个是oncreateview
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        view = inflater.inflate(R.layout.fragment_index, container, false);
        btn1 = view.findViewById(R.id.trans);
        btn2 = view.findViewById(R.id.note);
        btn3 = view.findViewById(R.id.onclass);
        btn4 = view.findViewById(R.id.commit);

        btn1.setOnClickListener(Change);
        btn2.setOnClickListener(Change);
        btn3.setOnClickListener(Change);
        btn4.setOnClickListener(Change);

        //获取资源id
        banner = view.findViewById(R.id.DE_banner);
        //创建图片地址集合
        List images = new ArrayList();
        images.add(R.drawable.material_design_3);
        images.add(R.drawable.material_design_4);
        images.add(R.drawable.material_design_5);

        banner.setImageLoader(new GlideImageLoader());
        banner.setImages(images);
        banner.start();

        AddView();
        Addgood();

        recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
        recyclerView_head=(RecyclerView)view.findViewById(R.id.recycler_head);
        LinearLayoutManager layoutManagerhead = new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());

        recyclerView_head.setLayoutManager(layoutManagerhead);
        recyclerView.setLayoutManager(layoutManager);

        MyAdapter adapter = new MyAdapter(goodsList);
        ButtonAdapter buttonAdapter=new ButtonAdapter(buttonList);
        recyclerView.setAdapter(adapter);
        recyclerView_head.setAdapter(buttonAdapter);
        return view;
    }


    private List<buttons> AddView(){

        for (int j = 0; j < 1; j++) {
            buttonList.add(new buttons(R.drawable.select_compute));
            buttonList.add(new buttons(R.drawable.select_delete));
            buttonList.add(new buttons(R.drawable.select_doc));
            buttonList.add(new buttons(R.drawable.select_music));
            buttonList.add(new buttons(R.drawable.select_notebook));
            buttonList.add(new buttons(R.drawable.select_pic));
            buttonList.add(new buttons(R.drawable.select_user));
            buttonList.add(new buttons(R.drawable.select_upload));
            buttonList.add(new buttons(R.drawable.select_compute));
            buttonList.add(new buttons(R.drawable.select_notebook));


        }
        return buttonList;
    }
    private List<goods> Addgood(){

        for (int j = 0; j < 10; j++) {
            goodsList.add(new goods("深度解析RocketMQ消息发送的高可用设计",R.drawable.nav_01_pre,"xiaoming","开发者"));

        }
        return goodsList;
    }

    private View.OnClickListener Change = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.trans:
                    Intent intent = new Intent(getContext(), FileActivity.class);
                    startActivity(intent);
                    break;
                case R.id.note:
                    Intent intent1 = new Intent(getContext(), OptimizeActivity.class);
                    startActivity(intent1);
                    break;
                case R.id.onclass:
                    Intent intent2 = new Intent(getContext(), PlayActivity.class);
                    startActivity(intent2);
                    break;
                case R.id.commit:
                    Intent intent4 = new Intent(getContext(), TransActivity.class);
                    startActivity(intent4);
                    break;


            }
        }
    };


    @Override
    public boolean onStartNestedScroll(@NonNull @NotNull View child, @NonNull @NotNull View target, int axes) {
        return false;
    }

    @Override
    public void onNestedScrollAccepted(@NonNull @NotNull View child, @NonNull @NotNull View target, int axes) {

    }

    @Override
    public void onStopNestedScroll(@NonNull @NotNull View target) {

    }

    @Override
    public void onNestedScroll(@NonNull @NotNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {

    }

    @Override
    public void onNestedPreScroll(@NonNull @NotNull View target, int dx, int dy, @NonNull @NotNull int[] consumed) {

    }

    @Override
    public boolean onNestedFling(@NonNull @NotNull View target, float velocityX, float velocityY, boolean consumed) {
        return false;
    }

    @Override
    public boolean onNestedPreFling(@NonNull @NotNull View target, float velocityX, float velocityY) {
        return false;
    }

    @Override
    public int getNestedScrollAxes() {
        return 0;
    }
}